﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _02WPF_DependencyProperties
{
    /// <summary>
    /// PropertyAttachedTest.xaml 的交互逻辑
    /// </summary>
    public partial class PropertyAttachedTest : Window
    {
        public PropertyAttachedTest()
        {
            InitializeComponent();
            Password = "123456";
            this.DataContext = this;
        }

        public string Password { get; set; }
    }

    public class PropertyAttachTest
    {
         public static readonly DependencyProperty PasswordProperty = DependencyProperty.RegisterAttached(
            "Password", typeof(string), typeof(PropertyAttachTest), new PropertyMetadata(default(string),new PropertyChangedCallback((s,e)=>(s as PasswordBox).Password=e.NewValue.ToString())));

         public static string GetPassword(DependencyObject obj)
         {
             return obj.GetValue(PasswordProperty).ToString();
         }
         public static void SetPassword(DependencyObject obj, string value)
         {
            obj.SetValue(PasswordProperty,value);

         }
    }
}

